package com.aia.ilp.web.json;

import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.SessionAware;

import com.aia.ilp.domain.Cust;
import com.aia.ilp.service.MainService;
import com.opensymphony.xwork2.ActionSupport;

public class CustomerVoteJson extends ActionSupport implements SessionAware {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(CustomerVoteJson.class);

	private static final long serialVersionUID = 1L;
	private Map session;
	private MainService mainService;
	private String mail;

	public void validate() {
		try {
			Cust cust = (Cust) session.get("customer");
			if (cust == null) {
				addActionError("没有登录或会话超时");
				return;
			}
		} catch (Exception e) {
			addActionError("Unknown Error");
			logger.error("Unknown Error", e);
			return;
		}
	}

	public String execute() throws Exception {
		try {
			if (logger.isDebugEnabled()) {
				logger.debug("CustomerActJson - start"); //$NON-NLS-1$
			}
			
			mainService.updateVote(this);
			if (logger.isDebugEnabled()) {
				logger.debug("CustomerActJson - end"); //$NON-NLS-1$
			}
			return SUCCESS;
		} catch (Exception e) {
			logger.error("Unknown Error" + e, e);
			throw new RuntimeException(e);
		}
	}

	public void setSession(Map session) {
		this.session = session;
	}
	
	public Map getSession() {
		return session;
	}

	public void setMainService(MainService mainService) {
		this.mainService = mainService;
	}

	public MainService getMainService() {
		return mainService;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	public String getMail() {
		return mail;
	}


}
